import { cityListAPI, hotCityListAPI } from '@/api'

const state = {
  cityList: [],
  hotCityList: []
}
const mutations = {
  GETCITYLIST (state, cityList) {
    state.cityList = cityList
  },
  GETHOTCITYLIST (state, hotCityList) {
    state.hotCityList = hotCityList
  }
}

const actions = {
  async confirmCityList (store) {
    try {
      const res = await cityListAPI()
      // console.log(res)
      const cityList = res.data.body
      store.commit('GETCITYLIST', cityList)
      // console.log(res)
      return Promise.resolve(res)
    } catch (error) {
      return Promise.reject(error)
    }
  },
  async confirmHotCityList (store) {
    try {
      const res = await hotCityListAPI()
      const hotCityList = res.data.body
      store.commit('GETHOTCITYLIST', hotCityList)
      return Promise.resolve(res)
    } catch (error) {
      return Promise.reject(error)
    }
  }
}

const getters = {
}

export default {
  state,
  mutations,
  actions,
  getters
}
